
%%
clear;
close all;

% Load data
load('CM_J_Model_5.mat')
bb = mean(betat_hat, 3);
load('CM_factors.mat');

% Create a figure
figure;
rdex = [3,2,5,1,4];
% Loop through the factors and create subplots for each
for ii = 1:5
    % First plot: bb(:,i) vs bb(:,6+2*i-1)
    subplot(3, 2, ii);
    i = rdex(ii);
    plot(bb(:,i), bb(:,5 + i ), 'ro', 'MarkerSize', 5); 
    hold on;
    plot(bb(:,i), bb(:,i), 'b:', 'LineWidth', 1);
    

  for j = 1:length(futures_name)
        text(bb(j, i), bb(j, 5 + i), futures_name{j}, 'FontSize', 8, 'HorizontalAlignment', 'left', 'VerticalAlignment', 'bottom');
  end


    % Linear regression line in black
    p = polyfit(bb(:,i), bb(:,5 + i ), 1);
    yfit = polyval(p, bb(:,i));
    plot(bb(:,i), yfit, 'k-', 'LineWidth', 1.5);  % Black regression line

      xlim([min(bb(:,i)) - 0.05*range(bb(:,i)), max(bb(:,i)) + 0.05*range(bb(:,i))]);
    ylim([min(bb(:,5 + i)) - 0.05*range(bb(:,5 + i)), max(bb(:,5 + i)) + 0.05*range(bb(:,5 + i))]);


    title(factors_name{i}, 'FontSize', 12);
    xlabel('Cont. Beta', 'FontSize', 10);
    ylabel('Jump Beta', 'FontSize', 10);
    %axis tight;
    grid on;


end

% Set the figure background to white for a cleaner look
set(gcf, 'Color', 'w');

